<html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css">
dt {
  font-style: italic;
  margin-top: 15px;
  margin-bottom: 3px;
  margin-left: 0px;
  border-bottom: 1px dotted black;
}
dd {
  margin-left: 10px;
}
table {
  border-collapse:collapse;
  border: 1px solid black;
  margin-top: 7px;
}
th {
  border: 1px solid black;
  padding: 3 7 3 7;
}
td {
  border: 1px solid black;
  padding: 3 7 3 7;
}
</style></head><body><p><a name="putfield"></a><b>putfield</b> :
  set value of object field : <a href="opcodes.html">index</a> : <a href="http://asm.objectweb.org/asm40/javadoc/user/org/objectweb/asm/MethodVisitor.html#visitFieldInsn(int,%20java.lang.String,%20java.lang.String,%20java.lang.String)">visitFieldInsn()</a></p><dl><dt>Description</dt><dd>putfield sets the value of the field identified by
&lt;field-spec&gt; in <i xmlns="">objectref</i> (a reference to an object) to the single
or double word value on the operand stack. For example, if you have the class:<br></br><pre>
    package xyz;
    class Point {
        public int xCoord, yCoord;
    };
</pre>
Then,
assuming p is an instance of the class Point, writing the Java expression:<br></br><pre>
    p.xCoord = 10;
</pre>
generates
JVM code like:<br></br><pre>
    aload_1                      ; push object in local varable 1 (i.e. p) onto the stack
    bipush 10                    ; push the integer 10 onto the stack
    putfield xyz/Point/xCoord I  ; set the value of the integer field p.xCoord to 10
</pre>
In
Jasmin, putfield takes two parameters, &lt;field-spec&gt; and
&lt;descriptor&gt;. &lt;field-spec&gt; provides <i xmlns="">classname</i>, the name of
the class that defines the field, as well as <i xmlns="">fieldname</i>, the name of the
field. In the example above, the &lt;field-spec&gt; is "xyz/Point/xCoord",
indicating that the <i xmlns="">classname</i> is called "xyz/Point" and the
<i xmlns="">fieldname</i> is "xCoord". &lt;descriptor&gt; indicates the type of data
held in the field, and is a standard Java type descriptor (see Chapter 4). In
the example above, &lt;descriptor&gt; is "I", since the field holds an
integer.<br></br>putfield first resolves <i xmlns="">classname</i> to a Java class. Then it
locates <i xmlns="">fieldname</i> in that class, determining the <i xmlns="">size</i> of the
field (in bytes) and its <i xmlns="">offset</i> (in bytes) from the base of the object
data. The type of the field must match &lt;descriptor&gt;. See Chapter 7 for a
full discussion of how fields are resolved<br></br>To set the value of the field, putfield pops either a 4-byte or 8-byte
quantity off the stack (depending on the field descriptor), and truncates it to
be <i xmlns="">width</i> bytes long. Then it sets the bytes starting at <i xmlns="">offset</i>
and extending for <i xmlns="">width</i> bytes in <i xmlns="">objectref</i>'s instance data to the
new value.</dd><dt>Exceptions</dt><dd>NullPointerException - <i xmlns="">objectref</i> is null</dd><dt>Notes</dt><dd>Fields cannot be overriden, although they can be 'shadowed'. For
example, with the two classes:<br></br><pre>
    class A { int x; }
and
    class B extends A { int x; }
</pre>
instances
of B will have storage for both the field "A/x" and the field "B/x". Which
field is accessed is determined by the class name given in
&lt;field-spec&gt;.</dd><dt>See also</dt><dd><a href="ref-getfield.html">getfield</a> <a href="ref-.html"></a> <a href="ref-putstatic.html">putstatic</a> <a href="ref-.html"></a> <a href="ref-getstatic.html">getstatic</a> </dd><dt>Stack</dt><dd><table xmlns="">
<tr>
<td>
<b>Before </b>
</td>
<td><b>After</b></td></tr>
<tr>
<td>value</td>
<td>...</td></tr>
<tr>
<td>objectref</td>
<td>...</td></tr>
<tr>
<td>...</td>
<td>...</td></tr>
</table></dd><dt>Bytecode</dt><dd><table xmlns="">
<tr>
<td>
<b> Type </b>
</td>
<td><b>Description</b></td></tr>
<tr>
<td>
u1 
</td>
<td>putfield
opcode = 0xB5 (181)
</td></tr>
<tr>
<td>
u2 
</td>
<td>index</td></tr>
</table></dd></dl></body></html>